<template>
  <div class="app-container">
    <div v-show="!showChild" class="out">
      <!-- <el-button
      class="marginRB10"
      type="success"
      @click="allAgree()"
      plain
      v-if="isShowAllAgree"
      >批量同意</el-button
    >
    <el-button
      class="marginRB10"
      type="warning"
      v-if="isShowAllAgree"
      @click="allFreeze()"
      plain
      >批量冻结</el-button
    > -->
      <el-button class="marginRB10" type="primary" @click="getExcel()" plain
        >导出EXCEL</el-button
      >
      <el-date-picker
        class="marginRB10"
        v-model="listQuery.start_at"
        type="datetime"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="选择起始日期"
      ></el-date-picker>
      <el-date-picker
        class="marginRB10"
        v-model="listQuery.end_at"
        type="datetime"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="选择结束日期"
      ></el-date-picker>
      <el-select
        filterable
        v-model="listQuery.status"
        class="filter-item marginRB10"
        placeholder="状态"
        style="width: 200px"
      >
        <el-option
          v-for="item in selectList2"
          :key="item.key"
          :label="item.lab"
          :value="item.key"
        ></el-option>
      </el-select>
      <el-input
        class="marginRB10"
        v-model="listQuery.search"
        placeholder="会长ID|公会ID"
        style="width: 200px"
        clearable
      ></el-input>
      <el-button
        type="primary"
        @click="getList"
        icon="el-icon-search"
        class="marginRB10"
        >搜索</el-button
      >
      <el-button
        type="primary"
        v-show="showChild"
        @click="back"
        class="marginRB10"
        >返回公会列表</el-button
      >
      <el-table
        v-show="!showChild"
        ref="dataList"
        :data="menuList"
        style="margin-bottom: 20px"
        row-key="id"
        border
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <el-table-column
          type="selection"
          v-if="isShowAllAgree"
          width="55"
        ></el-table-column>
        <el-table-column prop="id" label="序号"> </el-table-column>
        <el-table-column prop="count_time" label="时间">
          <template slot-scope="scope">
            {{ oneWeek(scope.row.count_time * 1000) }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="sociaty_id" label="公会ID"> </el-table-column> -->
        <el-table-column prop="sociaty_no" label="公会ID"> </el-table-column>
        <el-table-column prop="user_code" label="会长ID"> </el-table-column>
        <el-table-column prop="sociaty_name" label="公会名称">
        </el-table-column>
        <el-table-column prop="amount" label="房间流水"> </el-table-column>
        <!-- <el-table-column prop="rate" label="收益比例（%）"> </el-table-column> -->
        <!-- <el-table-column prop="amount" label="应发金币"> -->
        <el-table-column prop="should_amount" label="应发金币">
          <!-- <template slot-scope="scope">
          {{ fixedTwo((scope.row.amount * scope.row.rate) / 100) }}
        </template> -->
        </el-table-column>
        <el-table-column prop="reversal" label="冲正">
          <template slot-scope="scope">
            {{ scope.row.reversal ? scope.row.reversal * 1 : 0 }}
          </template>
        </el-table-column>
        <el-table-column prop="real_amount" label="预计实发金币">
          <template slot-scope="scope">
            {{
              fixedTwo(
                scope.row.should_amount * 1 +
                  (scope.row.reversal ? scope.row.reversal * 1 : 0)
              )
            }}
          </template>
        </el-table-column>
        <el-table-column prop="real_amount" label="实发金币">
          <!-- <template slot-scope="scope">
          {{
            fixedTwo(
              scope.row.amount * scope.row.rate * 0.01 +
                (scope.row.reversal ? scope.row.reversal * 1 : 0)
            )
          }}
        </template> -->
        </el-table-column>
        <el-table-column prop="rebate" label="金额">
          <template slot-scope="scope">
            ￥{{ fixedTwo(scope.row.real_amount / 100) }}
          </template>
        </el-table-column>
        <el-table-column prop="u_code" label="实发ID"> </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            {{ scope.row.status === 1 ? "待审核" : "" }}
            {{ scope.row.status === 2 ? "已发放" : "" }}
            {{ scope.row.status === 3 ? "已冻结" : "" }}
          </template>
        </el-table-column>
        <el-table-column prop="memo" label="备注">
          <!-- <template slot-scope="scope">
          {{ scope.row.memo === "null" ? "" : scope.row.memo }}
        </template> -->
        </el-table-column>
        <el-table-column min-width="400" label="操作">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.status === 1 && isShowFatherBtn"
              type="success"
              size="mini"
              @click="handleUpdate1(scope.row)"
              plain
              >同意</el-button
            >
            <el-button
              v-if="scope.row.status === 1 && isShowFatherBtn"
              type="warning"
              size="mini"
              @click="handleUpdate2(scope.row)"
              plain
              >冻结</el-button
            >
            <el-button
              v-if="scope.row.status === 3 && isShowFatherBtn"
              type="warning"
              size="mini"
              @click="handleUpdate5(scope.row)"
              plain
              >解冻</el-button
            >
            <el-button
              type="primary"
              size="mini"
              @click="handleUpdate3(scope.row)"
              plain
              >备注</el-button
            >
            <el-button
              v-if="scope.row.status !== 2"
              type="primary"
              size="mini"
              @click="handleUpdate4(scope.row)"
              plain
              >编辑</el-button
            >
            <el-button
              type="primary"
              size="mini"
              @click="getRoomListData(scope.row)"
              plain
              >公会下房间列表</el-button
            >
          </template>
          <!-- <el-table-column prop="房间模式" fixed="right" label="模式"> -->
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <cus-pagination
        v-show="total1 > 0"
        :total="total1"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.perPage"
        @pagination="getList"
      />
      <el-dialog
        v-dialogDrag
        title="编辑"
        :visible.sync="dialogFormVisible"
        @close="handleDialogClose"
      >
        <el-form
          ref="dataForm"
          :rules="rules"
          :model="form"
          label-position="right"
          label-width="120px"
          style="width: 400px; margin: 0 auto"
        >
          <el-form-item label="时间">
            {{ oneWeek(form.count_time * 1000) }}
          </el-form-item>
          <el-form-item label="公会ID">
            {{ form.sociaty_no }}
          </el-form-item>
          <el-form-item label="公会名称">
            {{ form.sociaty_name }}
          </el-form-item>
          <el-form-item label="房间流水">
            {{ form.amount }}
          </el-form-item>
          <el-form-item v-show="showChild" label="收益比例（%）" prop="rate">
            <el-input
              v-model="form.rate"
              disabled
              placeholder="请输入收益比例(%)"
            />
          </el-form-item>
          <el-form-item label="应发金币">
            {{ fixedTwo(form.amount * form.rate * 0.01) }}
          </el-form-item>
          <el-form-item label="实发金币">
            <template>
              {{
                fixedTwo(
                  form.amount * form.rate * 0.01 +
                    (form.reversal ? form.reversal * 1 : 0)
                )
              }}
            </template>
          </el-form-item>
          <el-form-item label="冲正" prop="reversal">
            <el-input-number
              :step="1"
              step-strictly
              v-model="form.reversal"
              placeholder="请输入冲正"
            ></el-input-number>
          </el-form-item>
          <el-form-item label="实发ID" prop="uid">
            <el-input
              type="number"
              v-model="form.u_code"
              placeholder="请输入实发ID"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center">
          <el-button @click="dialogFormVisible = false">
            取 消
          </el-button>
          <el-button type="primary" @click="submitForm()">
            确 认
          </el-button>
        </div>
      </el-dialog>
      <el-dialog
        v-dialogDrag
        title="编辑备注"
        :visible.sync="dialogFormVisible2"
        @close="handleDialogClose2"
      >
        <el-form
          ref="dataForm2"
          :rules="rules2"
          :model="form2"
          label-position="right"
          label-width="140px"
          style="width: 400px; margin: 0 auto"
        >
          <el-form-item label="备注" prop="memo">
            <el-input v-model="form2.memo" placeholder="请输入备注" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center">
          <el-button @click="dialogFormVisible2 = false">
            取 消
          </el-button>
          <el-button type="primary" @click="submitForm2()">
            确 认
          </el-button>
        </div>
      </el-dialog>
    </div>
    <div v-show="showChild" class="inner">
      <!-- <el-button
      class="marginRB10"
      type="success"
      @click="allAgree()"
      plain
      v-if="isShowAllAgree"
      >批量同意</el-button
    >
    <el-button
      class="marginRB10"
      type="warning"
      v-if="isShowAllAgree"
      @click="allFreeze()"
      plain
      >批量冻结</el-button
    > -->
      <!-- <el-button class="marginRB10" type="primary" @click="getExcel()" plain
        >导出EXCEL</el-button
      >
      <el-date-picker
        class="marginRB10"
        v-model="listQuery.start_at"
        type="datetime"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="选择起始日期"
      ></el-date-picker>
      <el-date-picker
        class="marginRB10"
        v-model="listQuery.end_at"
        type="datetime"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="选择结束日期"
      ></el-date-picker> -->
      <!-- <el-select filterable
        v-model="listQuery.status"
        class="filter-item marginRB10"
        placeholder="状态"
        style="width: 200px"
      >
        <el-option
          v-for="item in selectList2"
          :key="item.key"
          :label="item.lab"
          :value="item.key"
        ></el-option>
      </el-select> -->
      <!-- <el-input
        class="marginRB10"
        v-model="listQuery.search"
        placeholder="房间ID|房主ID"
        style="width: 200px"
        clearable
      ></el-input>
      <el-button
        type="primary"
        @click="getRoomListData"
        icon="el-icon-search"

        class="marginRB10"
        >搜索</el-button
      > -->
      <el-button
        type="primary"
        v-show="showChild"
        @click="back"
        class="marginRB10"
        >返回公会列表</el-button
      >
      <el-table
        v-show="showChild"
        ref="roomDataList"
        :data="roomList"
        style="margin-bottom: 20px"
        row-key="id"
        border
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <el-table-column
          type="selection"
          v-if="isShowAllAgree"
          width="55"
        ></el-table-column>
        <el-table-column prop="id" label="序号"> </el-table-column>
        <el-table-column prop="count_time" label="时间">
          <template slot-scope="scope">
            {{ oneWeek(scope.row.count_time * 1000) }}
          </template>
        </el-table-column>
        <el-table-column prop="room_code" label="房间ID"> </el-table-column>
        <el-table-column prop="room_name" label="房间名称"> </el-table-column>
        <el-table-column prop="room_type_name" label="房间类型">
        </el-table-column>
        <el-table-column prop="room_user_id" label="房主ID"> </el-table-column>
        <!-- <el-table-column prop="user_code" label="房主ID"> </el-table-column> -->
        <el-table-column prop="nickname" label="房主昵称"> </el-table-column>
        <el-table-column prop="amount" label="房间流水"> </el-table-column>
        <el-table-column prop="rate" label="收益比例（%）"> </el-table-column>
        <el-table-column prop="amount" label="应发金币">
          <template slot-scope="scope">
            {{ fixedTwo((scope.row.amount * scope.row.rate) / 100) }}
          </template>
        </el-table-column>
        <el-table-column prop="reversal" label="冲正"></el-table-column>
        <el-table-column prop="real_amount" label="实发金币">
          <template slot-scope="scope">
            {{
              fixedTwo(
                scope.row.amount * scope.row.rate * 0.01 +
                  (scope.row.reversal ? scope.row.reversal * 1 : 0)
              )
            }}
          </template>
        </el-table-column>
        <el-table-column prop="1" label="等价金额">
          <template slot-scope="scope">
            ￥{{
              fixedTwo(
                (scope.row.amount * scope.row.rate * 0.01 +
                  (scope.row.reversal ? scope.row.reversal * 1 : 0)) /
                  100
              )
            }}
          </template>
        </el-table-column>
        <el-table-column prop="u_code" label="实发ID"> </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            {{ scope.row.status === 1 ? "待审核" : "" }}
            {{ scope.row.status === 2 ? "已发放" : "" }}
            {{ scope.row.status === 3 ? "已冻结" : "" }}
          </template>
        </el-table-column>
        <el-table-column prop="memo" label="备注">
          <!-- <template slot-scope="scope">
          {{ scope.row.memo === "null" ? "" : scope.row.memo }}
        </template> -->
        </el-table-column>
        <el-table-column min-width="300" label="操作">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.status === 1"
              type="success"
              size="mini"
              @click="handleUpdate11(scope.row)"
              plain
              >同意</el-button
            >
            <el-button
              v-if="scope.row.status === 1"
              type="warning"
              size="mini"
              @click="handleUpdate22(scope.row)"
              plain
              >冻结</el-button
            >
            <el-button
              v-if="scope.row.status === 3"
              type="warning"
              size="mini"
              @click="handleUpdate55(scope.row)"
              plain
              >解冻</el-button
            >
            <el-button
              type="primary"
              size="mini"
              @click="handleUpdate33(scope.row)"
              plain
              >备注</el-button
            >
            <el-button
              v-if="scope.row.status !== 2"
              type="primary"
              size="mini"
              @click="handleUpdate44(scope.row)"
              plain
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <cus-pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.perPage"
        @pagination="getRoomListData"
      />
      <el-dialog
        v-dialogDrag
        title="编辑"
        :visible.sync="dialogFormVisible"
        @close="handleDialogClose"
      >
        <el-form
          ref="dataForm"
          :rules="rules"
          :model="form"
          label-position="right"
          label-width="120px"
          style="width: 400px; margin: 0 auto"
        >
          <el-form-item label="时间">
            {{ oneWeek(form.count_time * 1000) }}
          </el-form-item>
          <el-form-item label="房间ID">
            {{ form.room_code }}
          </el-form-item>
          <!-- <el-form-item label="公会名称">
            {{ form.sociaty_name }}
          </el-form-item> -->
          <el-form-item label="房间名称">
            {{ form.room_name }}
          </el-form-item>
          <el-form-item label="房间流水">
            {{ form.amount }}
          </el-form-item>
          <el-form-item v-show="showChild" label="收益比例（%）" prop="rate">
            <el-input
              v-model="form.rate"
              disabled
              placeholder="请输入收益比例(%)"
            />
          </el-form-item>
          <el-form-item label="应发金币">
            {{ fixedTwo(form.amount * form.rate * 0.01) }}
          </el-form-item>
          <el-form-item label="实发金币">
            <template>
              {{
                fixedTwo(
                  form.amount * form.rate * 0.01 +
                    (form.reversal ? form.reversal * 1 : 0)
                )
              }}
            </template>
          </el-form-item>
          <el-form-item label="冲正" prop="reversal">
            <el-input-number
              :step="1"
              step-strictly
              v-model="form.reversal"
              placeholder="请输入冲正"
            ></el-input-number>
          </el-form-item>
          <el-form-item label="实发ID" prop="uid">
            <el-input
              type="number"
              v-model="form.u_code"
              placeholder="请输入实发ID"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center">
          <el-button @click="dialogFormVisible = false">
            取 消
          </el-button>
          <el-button type="primary" @click="submitForm()">
            确 认
          </el-button>
        </div>
      </el-dialog>
      <el-dialog
        v-dialogDrag
        title="编辑备注"
        :visible.sync="dialogFormVisible2"
        @close="handleDialogClose2"
      >
        <el-form
          ref="dataForm2"
          :rules="rules2"
          :model="form2"
          label-position="right"
          label-width="140px"
          style="width: 400px; margin: 0 auto"
        >
          <el-form-item label="备注" prop="memo">
            <el-input v-model="form2.memo" placeholder="请输入备注" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center">
          <el-button @click="dialogFormVisible2 = false">
            取 消
          </el-button>
          <el-button type="primary" @click="submitForm2()">
            确 认
          </el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  saveData,
  deleteData,
  updateData,
  listData,
  statisticAgree,
  statisticFreeze,
  statisticUnfreeze,
  statisticExport
} from "@/api/unionWater/roomListWater";
import {
  roomListData,
  fatherAgree,
  updateChild,
  updateFather
} from "@/api/unionWater/waterList";
export default {
  data() {
    return {
      childHasOption: false,
      outId: "", //公会id
      outTime: "",
      showChild: false,
      isShowAllAgree: true, // 是否显示全部同意按钮 （默认显示）如果父级或者子选项有已经操作过的（冻结|同意）则不允许进行’全部‘操作
      isShowFatherBtn: true,
      listLoading: true,
      total: 0,
      total1: 0,
      roomList: [],
      listQuery: {
        page: 1,
        perPage: 10
      },
      listQueryChild: {
        page: 1,
        perPage: 10
      },
      selectList2: [
        { key: undefined, lab: "全部分类" },
        { key: "1", lab: "待审核 " },
        { key: "2", lab: "已发放" },
        { key: "3", lab: "已冻结" }
      ],
      menuList: [],
      dialogFormVisible: false,
      dialogFormVisible2: false,
      dialogStatus: "",
      titleMap: {
        update: "编辑",
        create: "增加"
      },
      form: {
        id: undefined,
        count_time: undefined,
        sociaty_id: undefined,
        sociaty_no: undefined,
        sociaty_name: undefined,
        room_name: undefined,
        amount: undefined,
        rate: undefined,
        real_amount: undefined,
        uid: undefined,
        u_code: undefined,
        reversal: 0
      },
      form2: {
        sociaty_id: undefined,
        memo: undefined
      },
      rules: {
        rate: [{ required: true, message: "请输入收益比例", trigger: "blur" }],
        uid: [
          { required: true, message: "请输入实发ID", trigger: "blur" }
          // { len: 6, message: "实发ID必须为6个字符", trigger: "blur" },
        ]
      },
      rules2: {
        memo: [{ required: true, message: "请输入备注", trigger: "blur" }]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    fixedTwo(i) {
      let num = i.toFixed(3);
      return num.substring(0, num.lastIndexOf(".") + 3);
    },
    back() {
      this.showChild = !this.showChild;
    },
    // 获取子级的列表
    getRoomListData(e) {
      let urlData = "?";
      if (this.listQuery.page) {
        urlData = urlData + `page=${this.listQuery.page}&`;
      }
      if (this.listQuery.perPage) {
        urlData = urlData + `perPage=${this.listQuery.perPage}`;
      }
      if (this.listQuery.search) {
        urlData = urlData + `&search=${this.listQuery.search}`;
      }
      if (this.listQuery.start_at) {
        urlData = urlData + `&start_at=${this.listQuery.start_at}`;
      }
      if (this.listQuery.end_at) {
        urlData = urlData + `&end_at=${this.listQuery.end_at}`;
      }
      if (this.listQuery.status) {
        urlData = urlData + `&status=${this.listQuery.status}`;
      }
      // 上一层的公会id
      let sociaty_id;
      let time;
      if (e) {
        // if (!localStorage.getItem("sociaty_id")) {
        //   localStorage.setItem("sociaty_id", e.sociaty_id);
        // }
        // if (!localStorage.getItem("count_time")) {
        //   localStorage.setItem("count_time", e.count_time);
        // }
        // if (
        //   localStorage.getItem("sociaty_id") &&
        //   localStorage.getItem("sociaty_id") != e.sociaty_id
        // ) {
        //   localStorage.setItem("sociaty_id", e.sociaty_id);
        // }
        // if (
        //   localStorage.getItem("count_time") &&
        //   localStorage.getItem("count_time") != e.count_time
        // ) {
        //   localStorage.setItem("count_time", e.count_time);
        // }
        time = e.count_time;
        sociaty_id = e.sociaty_id;
        this.outId = e.sociaty_id;
        this.outTime = e.count_time;
      } else {
        // this.outId = e.sociaty_id;
      }
      // this.showChild = !this.showChild;
      this.showChild = true;
      this.listLoading = true;
      let data = sociaty_id ? sociaty_id : this.outId;
      let count_time = time ? time : this.outTime;

      // let s = localStorage.getItem("sociaty_id");
      // let c = localStorage.getItem("count_time");
      roomListData(
        urlData + "&sociaty_id=" + data + "&count_time=" + count_time
      ).then(response => {
        this.roomList = response.data.list;
        if (e.status === 2 || e.status === 3) {
          for (let i = 0; i < this.roomList.length; i++) {
            this.roomList[i].status = -1;
          }
        }
        this.total = response.data.list.length;
        this.listLoading = false;
      });
    },
    // 获取父级的列表
    getList() {
      this.listLoading = true;
      let urlData = "?";
      if (this.listQuery.page) {
        urlData = urlData + `page=${this.listQuery.page}&`;
      }
      if (this.listQuery.perPage) {
        urlData = urlData + `perPage=${this.listQuery.perPage}`;
      }
      if (this.listQuery.search) {
        urlData = urlData + `&search=${this.listQuery.search}`;
      }
      if (this.listQuery.start_at) {
        urlData = urlData + `&start_at=${this.listQuery.start_at}`;
      }
      if (this.listQuery.end_at) {
        urlData = urlData + `&end_at=${this.listQuery.end_at}`;
      }
      if (this.listQuery.status) {
        urlData = urlData + `&status=${this.listQuery.status}`;
      }

      listData(urlData).then(response => {
        this.menuList = response.data.list;
        this.total1 = response.data.meta.total;
        let fatherId = []; // 父级id集合
        let fatherCountTime = []; // 父级时间集合
        let fatherStatus = []; // 父级状态集合
        for (let i = 0; i < this.menuList.length; i++) {
          fatherId.push(this.menuList[i].sociaty_id);
          fatherCountTime.push(this.menuList[i].count_time);
          fatherStatus.push(this.menuList[i].status);
        }
        // 父级是否有操作过的
        let flag = fatherStatus.some(item => item === 2 || item === 3);
        if (flag) {
          this.isShowAllAgree = false;
        } else {
          this.isShowAllAgree = true;
        }

        // 子级（房间）是否有操作过的
        for (let i = 0; i < fatherId.length; i++) {
          this.getChildList(fatherId[i], fatherCountTime[i]);
        }
        this.listLoading = false;
      });
    },
    // 查看子级是否有操作过的
    getChildList(id, count_time) {
      let data = id;
      roomListData("?sociaty_id=" + data + "&count_time=" + count_time).then(
        response => {
          let roomList = response.data.list;
          let childFlag = roomList.some(
            item => item.status === 2 || item.status === 3
          );
          if (childFlag) {
            this.isShowAllAgree = false;
            // this.isShowFatherBtn = false;
            this.menuList.find(item => {
              if (item.sociaty_id === data) {
                item.status = -1;
              }
            });
          }
          if (!childFlag) {
            this.isShowAllAgree = true;
            this.isShowFatherBtn = true;
          }
          // this.roomList);
          this.total = response.data.list.length;
          this.listLoading = false;
        }
      );
    },
    handleCreate(row) {
      this.resetForm();
      this.dialogStatus = "create";
      this.dialogFormVisible = true;
    },
    // 房间的方法是复数(11,22,33,44,55)
    handleUpdate1(row) {
      let data = { ids: JSON.stringify([row.id]) };
      this.loadingFun();
      // statisticAgree(data).then((response) => {
      //   this.loadingFun().close();
      //   if (response.code === 200) {
      //     this.getList();
      //     this.submitOk("成功");
      //   } else {
      //     this.submitFail("失败");
      //   }
      // });
      fatherAgree(data).then(response => {
        this.loadingFun().close();
        if (response.code === 200) {
          this.getList();
          this.submitOk("成功");
        } else {
          this.submitFail("失败");
        }
      });
    },
    loadingFun() {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      return loading;
    },
    handleUpdate11(row) {
      let data = { ids: JSON.stringify([row.id]) };
      this.loadingFun();
      statisticAgree(data).then(response => {
        this.loadingFun().close();
        if (response.code === 200) {
          this.getRoomListData();
          this.submitOk("成功");
        } else {
          this.submitFail("失败");
        }
      });
    },
    handleUpdate2(row) {
      let data = { ids: JSON.stringify([row.id]) };
      this.loadingFun();
      statisticFreeze(data).then(response => {
        this.loadingFun().close();
        if (response.code === 200) {
          this.getList();
          this.submitOk("成功");
        } else {
          this.submitFail("失败");
        }
      });
    },
    handleUpdate22(row) {
      let data = { ids: JSON.stringify([row.id]) };
      this.loadingFun();
      statisticFreeze(data).then(response => {
        this.loadingFun().close();
        if (response.code === 200) {
          // this.getRoomListData();
          if (this.showChild) {
            this.getRoomListData();
            this.getList();
            this.showChild = true;
          } else {
            this.getList();
            this.showChild = false;
          }
          this.submitOk("成功");
        } else {
          this.submitFail("失败");
        }
      });
    },
    // 备注
    handleUpdate3(row) {
      this.form2 = [];
      this.form2.id = row.id;
      this.form2.memo = row.memo;

      this.dialogFormVisible2 = true;

      this.form2 = Object.assign({}, this.form2);
    },
    handleUpdate33(row) {
      this.form2 = [];
      this.form2.id = row.id;
      this.form2.memo = row.memo;

      this.dialogFormVisible2 = true;

      this.form2 = Object.assign({}, this.form2);
    },
    // 编辑
    handleUpdate4(row) {
      this.form = [];
      this.form.id = row.id;
      this.form.count_time = row.count_time;
      this.form.sociaty_id = row.sociaty_id;
      this.form.sociaty_no = row.sociaty_no;
      this.form.sociaty_name = row.sociaty_name;
      this.form.amount = row.amount;
      this.form.rate = row.rate;
      // this.form.real_rate = row.real_rate;
      this.form.real_amount = row.real_amount;
      this.form.uid = row.user_code.toString();
      this.form.u_code = row.u_code;
      this.form.reversal = row.reversal * 1;

      this.dialogStatus = "update";
      this.dialogFormVisible = true;

      this.form = Object.assign({}, this.form);
    },
    handleUpdate44(row) {
      this.form = [];
      this.form.id = row.id;
      this.form.count_time = row.count_time;
      this.form.sociaty_id = row.sociaty_id;
      this.form.room_code = row.room_code;
      this.form.sociaty_name = row.sociaty_name;
      this.form.room_name = row.room_name;
      this.form.amount = row.amount;
      this.form.rate = row.rate;
      // this.form.real_rate = row.real_rate;
      this.form.real_amount = row.real_amount;
      this.form.uid = row.u_code.toString();
      this.form.u_code = row.u_code;
      this.form.reversal = row.reversal * 1;
      this.dialogStatus = "update";
      this.dialogFormVisible = true;

      this.form = Object.assign({}, this.form);
    },
    // 解冻
    handleUpdate5(row) {
      let data = { id: row.id };
      this.loadingFun();

      statisticUnfreeze(data).then(response => {
        this.loadingFun().close();
        if (response.code === 200) {
          this.getList();
          this.submitOk("成功");
        } else {
          this.submitFail("失败");
        }
      });
    },
    handleUpdate55(row) {
      this.loadingFun();
      let data = { id: row.id };
      statisticUnfreeze(data).then(response => {
        this.loadingFun().close();
        if (response.code === 200) {
          // this.getRoomListData();
          this.submitOk("成功");
          if (this.showChild) {
            this.getRoomListData();
            this.getList();
            this.showChild = true;
          } else {
            this.getList();
            this.showChild = false;
          }
        } else {
          this.submitFail("失败");
        }
      });
    },
    handleDelete(row) {
      let data = { ids: row.id };
      deleteData(data).then(response => {
        if (response.code === 200) {
          this.getList();
          this.submitOk("删除成功");
        } else {
          this.submitFail("删除失败");
        }
      });
    },
    getExcel() {
      let urlData = "?type=1";
      if (this.listQuery.start_at) {
        urlData = urlData + `&start_at=${this.listQuery.start_at}`;
      }
      if (this.listQuery.end_at) {
        urlData = urlData + `&end_at=${this.listQuery.end_at}`;
      }
      if (this.listQuery.status) {
        urlData = urlData + `&status=${this.listQuery.status}`;
      }
      if (this.listQuery.search) {
        urlData = urlData + `&search=${this.listQuery.search}`;
      }
      statisticExport(urlData).then(response => {
        location.href = response.data.download_url;
      });
    },
    allAgree() {
      this.loadingFun();
      let delNum = [];
      this.$refs.dataList.selection.forEach(k => {
        delNum.push(k.id);
      });
      if (delNum.length === 0) {
        this.loadingFun().close();
        return;
      }
      let data = { ids: JSON.stringify(delNum) };
      // statisticAgree(data).then((response) => {
      //   this.loadingFun().close();
      //   if (response.code === 200) {
      //     this.getList();
      //     this.submitOk("成功");
      //   } else {
      //     this.submitFail("失败");
      //   }
      // });
      fatherAgree(data).then(response => {
        this.loadingFun().close();
        if (response.code === 200) {
          this.getList();
          this.submitOk("成功");
        } else {
          this.submitFail("失败");
        }
      });
    },
    allFreeze() {
      // this.$refs.dataList.selection)
      this.loadingFun();

      let delNum = [];
      this.$refs.dataList.selection.forEach(k => {
        delNum.push(k.id);
      });
      if (delNum.length === 0) {
        this.loadingFun().close();
        return;
      }
      let data = { ids: JSON.stringify(delNum) };
      statisticFreeze(data).then(response => {
        this.loadingFun().close();
        if (response.code === 200) {
          this.getList();
          this.submitOk("成功");
        } else {
          this.submitFail("失败");
        }
      });
    },

    submitForm() {
      this.$refs["dataForm"].validate(valid => {

        if (!valid) {
          return;
        }
        let formData = new FormData();
        // for(let item in this.form){this.form[item] === undefined? '':formData.append(item, this.form[item]);}
        formData.append("id", this.form["id"]);
        formData.append("uid", this.form["u_code"]);
        formData.append("rate", this.form["rate"]);
        formData.append(
          "reversal",
          this.form["reversal"] ? this.form["reversal"] * 1 : 0
        );

        // saveData(formData).then((response) => {
        //   this.loadingFun().close();
        //   if (response.code === 200) {
        //     if (this.showChild) {
        //       this.getRoomListData();
        //       this.showChild = true;
        //     } else {
        //       this.getList();
        //       this.showChild = false;
        //     }
        //     this.$notify({
        //     type:'success',
        //     message: '操作成功',
        //     position: 'bottom-right',
        //     showClose: false,
        //     duration: 3000
        // });;
        //     this.dialogFormVisible = false;
        //   } else {
        //     this.submitFail(response.message);
        //   }
        // });
        //  内层的编辑
        if (this.showChild) {
          updateChild(formData).then(response => {
            if (response.code === 200) {
              let data = {
                count_time: this.menuList[0].count_time,
                sociaty_id: this.outId
              };
              if (this.showChild) {
                this.getRoomListData(data);
                this.showChild = true;
              } else {
                this.getList();
                this.showChild = false;
              }
              this.$notify({
                type: "success",
                message: "操作成功",
                position: "bottom-right",
                showClose: false,
                duration: 3000
              });
              this.dialogFormVisible = false;
            } else {
              this.$message({
                message: response.message,
                type: "error"
              });
            }
          });
        } else {
          updateFather(formData).then(response => {
            // this.loadingFun().close();
            if (response.code === 200) {
              let data = {
                count_time: this.menuList[0].count_time,
                sociaty_id: this.outId
              };
              if (this.showChild) {
                this.getRoomListData(data);
                this.showChild = true;
              } else {
                this.getList();
                this.showChild = false;
              }
              this.$notify({
                type: "success",
                message: "操作成功",
                position: "bottom-right",
                showClose: false,
                duration: 3000
              });
              this.dialogFormVisible = false;
            } else {
              this.$message({
                message: response.message,
                type: "error"
              });
            }
          });
        }
        // 外层的编辑
      });
    },
    // 提交备注
    submitForm2() {
      this.$refs["dataForm2"].validate(valid => {
        if (!valid) {
          return;
        }
        let formData = new FormData();
        for (let item in this.form2) {
          this.form2[item] === undefined
            ? ""
            : formData.append(item, this.form2[item] ? this.form2[item] : "");
        }
        updateData(formData).then(response => {
          if (response.code === 200) {
            // this.getList();
            if (this.showChild) {
              this.getRoomListData();
              this.showChild = true;
            } else {
              this.getList();
              this.showChild = false;
            }
            // this.getRoomListData();
            // this.showChild = true;
            this.$notify({
              type: "success",
              message: "操作成功",
              position: "bottom-right",
              showClose: false,
              duration: 3000
            });
            this.dialogFormVisible2 = false;
          } else {
            this.$message({
              message: response.message,
              type: "error"
            });
          }
        });
      });
    },
    resetForm() {
      this.form = {
        id: undefined,
        count_time: undefined,
        sociaty_id: undefined,
        sociaty_name: undefined,
        room_name: undefined,
        amount: undefined,
        rate: undefined,
        real_amount: undefined,
        uid: undefined,
        u_code: undefined
      };
    },
    dataTime(val) {
      let oToday = new Date(val);
      let currentDay = oToday.getDay();
      if (currentDay === 0) {
        currentDay = 7;
      }
      let mondayTime =
        oToday.getTime() - (currentDay - 1) * 24 * 60 * 60 * 1000;
      let sundayTime =
        oToday.getTime() + (7 - currentDay) * 24 * 60 * 60 * 1000;
      return (
        this.timestampToTime(mondayTime) +
        "~" +
        this.timestampToTime(sundayTime)
      );
    },
    // 初始化开始结束
    week() {
      let oToday = new Date();
      let currentDay = oToday.getDay();
      if (currentDay === 0) {
        currentDay = 7;
      }
      let mondayTime =
        oToday.getTime() -
        (currentDay - 1) * 24 * 60 * 60 * 1000 -
        7 * 24 * 60 * 60 * 1000;
      let sundayTime =
        oToday.getTime() +
        (7 - currentDay) * 24 * 60 * 60 * 1000 -
        7 * 24 * 60 * 60 * 1000;
      this.listQuery.start_at = mondayTime;
      this.listQuery.end_at = sundayTime;
    },
    oneWeek(val) {
      let mondayTime = val - 7 * 24 * 60 * 60 * 1000;
      let sundayTime = val;
      return (
        this.timestampToTime(mondayTime) +
        "~" +
        this.timestampToTime(sundayTime - 24 * 60 * 60 * 1000)
      );
    },
    getDate(data) {
      let date = new Date(data);
      let Y = date.getFullYear() + "-";
      let M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      let D =
        (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
      let h =
        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
      let m =
        (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
        ":";
      let s =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      return Y + M + D + h + m + s;
    },
    timestampToTime(timestamp) {
      let date = new Date(timestamp);
      let Y = date.getFullYear() + "-";
      let M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      let D =
        (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
      let strDate = Y + M + D;
      return strDate;
    },
    // 监听dialog关闭时的处理事件
    handleDialogClose() {
      if (this.$refs["dataForm"]) {
        this.$refs["dataForm"].clearValidate(); // 清除整个表单的校验
      }
    },
    handleDialogClose2() {
      if (this.$refs["dataForm2"]) {
        this.$refs["dataForm2"].clearValidate(); // 清除整个表单的校验
      }
    }
  }
};
</script>
<style>
.customClass {
  width: 70%;
  max-width: 100%;
}
</style>
